# 简易 Makefile for Linux / MinGW Windows
CC := gcc
CFLAGS := -Wall -O2 -Iinclude
BUILD_DIR := build
BIN := $(BUILD_DIR)/simple_stack_demo

SRCS := $(wildcard src/net/*.c) $(wildcard src/drivers/*.c)
SRCS += examples/demo.c

OBJS := $(patsubst %.c, $(BUILD_DIR)/%.o, $(notdir $(SRCS)))

.PHONY: all clean dirs

all: dirs $(BIN)

dirs:
	@mkdir -p $(BUILD_DIR)

# compile rules (map notdir .c -> build/<name>.o)
$(BUILD_DIR)/%.o: src/net/%.c
	$(CC) $(CFLAGS) -c $< -o $@

$(BUILD_DIR)/%.o: src/drivers/%.c
	$(CC) $(CFLAGS) -c $< -o $@

$(BUILD_DIR)/%.o: examples/%.c
	$(CC) $(CFLAGS) -c $< -o $@

$(BIN): $(foreach s,$(SRCS),$(BUILD_DIR)/$(notdir $(s:.c=.o)))
	$(CC) -o $@ $^ -lpcap

clean:
	-rm -rf $(BUILD_DIR)
